<template>
    <el-tabs :tab-position="tabPosition" v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="设置模型" name="setCalculate">
            <setCalculate></setCalculate>
        </el-tab-pane>
        <el-tab-pane label="成本汇总表" name="first">
            <costCollect></costCollect>
        </el-tab-pane>
        <el-tab-pane label="收入面积汇总表" name="second">
            <building></building>
        </el-tab-pane>
        <el-tab-pane label="测算收入表" name="third">
            <income></income>
        </el-tab-pane>
        <el-tab-pane label="单体成本分摊表(一)" name="fourth">
            <danti1></danti1>
        </el-tab-pane>
        <el-tab-pane label="单体成本分摊明细表（二）" name="danti2">
            <danti2></danti2>
        </el-tab-pane>
        <el-tab-pane label="单体成本之配套成本分摊计算（三）" name="danti3">
            <danti3></danti3>
        </el-tab-pane>
        <el-tab-pane label="单体成本之专属成本分摊计算表（四）" name="danti4">
            <danti4></danti4>
        </el-tab-pane>
        <el-tab-pane label="专属成本分摊表" name="exclusive">
            <exclusive></exclusive>
        </el-tab-pane>
        <el-tab-pane label="成本合计明细表" name="mingxi1">
            <mingxi1></mingxi1>
        </el-tab-pane>
        <el-tab-pane label="分摊成本合计明细表" name="mingxi2">
            <mingxi2></mingxi2>
        </el-tab-pane>
        <el-tab-pane label="分摊成本合计明细表(已售)" name="mingxi3">
            <mingxi3></mingxi3>
        </el-tab-pane>
        <el-tab-pane label="分摊成本合计明细表(未售)" name="mingxi4">
            <mingxi4></mingxi4>
        </el-tab-pane>
        <el-tab-pane label="开发成本分配表" name="kfcbfpb">
            <kfcbfpb></kfcbfpb>
        </el-tab-pane>
        <el-tab-pane label="增值税测算表" name="zzscsb">
            <zzscsb></zzscsb>
        </el-tab-pane>
        <el-tab-pane label="土地增值税清算税金明细表" name="qssj">
            <qssj></qssj>
        </el-tab-pane>
        <el-tab-pane label="土地增值税清算结果表（汇总）" name="huizong">
            <huizong></huizong>
        </el-tab-pane>
        
    </el-tabs>
</template>


<script>

import setCalculate from './setCalculate'
import costCollect from './costCollect'
import building from './building'
import income from './income'
import danti1 from './danti1'
import danti2 from './danti2'
import danti3 from './danti3'
import danti4 from './danti4'
import exclusive from './exclusive'
import mingxi1 from './mingxi1'
import mingxi2 from './mingxi2'
import mingxi3 from './mingxi3'
import mingxi4 from './mingxi4'
import kfcbfpb from './kfcbfpb'
import zzscsb from './zzscsb'
import qssj from './qssj'
import huizong from './huizong'



import { getToken } from '@/utils/auth'
import calculateApi from '@/api/calculate'


export default {
    data() {
        return {
            tabPosition: 'left',
            calculate_id: '',
            calculateCostCollect: [],
            activeName: 'huizong',



        }
    },
    methods: {

        handleClick(tab, event) {
            console.log(tab, event);
        },

        //上传文件
        importExcel(file) {

            const formData = new FormData()
            formData.append('excel', file.file)

            this.$axios({
                method: 'post',
                url: '/calculate_cost_summary/add_excel/' + this.calculate_id,
                headers: { 'Authorization': 'Bearer ' + getToken() },
                timeout: 30000,
                data: formData
            }).then(res => {

                this.handleSuccess();

            })

        },

        //上传成功后的回调
        handleSuccess() {
            this.getCalculateCostCollectList();
        },






        //获取成本汇总表数据
        getCalculateCostCollectList() {
            calculateApi.getCalculateCostCollect(this.calculate_id).then(response => {
                this.calculateCostCollect = response.data.list;
            })
        },

        //vue自动求和
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '总价';
                    return;
                }
                const values = data.map(item => Number(item[column.property]));
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);
                    sums[index] = sums[index].toFixed(2);
                    // sums[index] += ' ';
                } else {
                    sums[index] = 'N/A';
                }

            });

            return sums;
        }
    },

    created() {
        var query = this.$route.query;
        if (query.id) {
            this.calculate_id = query.id;

        }

        this.getCalculateCostCollectList();

    },

    components: {
        setCalculate,
        costCollect,
        building,
        income,
        danti1,
        danti2,
        danti3,
        danti4,
        exclusive,
        mingxi1,
        mingxi2,
        mingxi3,
        mingxi4,
        kfcbfpb,
        zzscsb,
        qssj,
        huizong,
    }
}
</script>

<style></style>